package org.jadestudio.home.action;

import java.io.PrintWriter;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import org.jadestudio.home.service.FeedService;
import org.jadestudio.home.service.LaboratoryService;
import org.jadestudio.home.service.LeaderboardService;

public class IndexLaboratoryAction extends Action {
	private LaboratoryService laboratoryService;
	private LeaderboardService leaderboardService;
	private FeedService feedService;	
	
	public LaboratoryService getLaboratoryService() {
		return laboratoryService;
	}
	public void setLaboratoryService(LaboratoryService laboratoryService) {
		this.laboratoryService = laboratoryService;
	}
	
	public LeaderboardService getleaderboardService() {
		return leaderboardService;
	}
	public void setleaderboardService(LeaderboardService leaderboardService) {
		this.leaderboardService = leaderboardService;
	}
	
	public FeedService getFeedService() {
		return feedService;
	}
	public void setFeedService(FeedService feedService) {
		this.feedService = feedService;
	}
	
	public IndexLaboratoryAction(){
		
	}
	/**
	 * 加载数据
	 */
	@SuppressWarnings("unchecked")
	public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request,
            HttpServletResponse response) throws Exception{
		
		// 加载实验室
		List<java.util.Map> laboratory = laboratoryService.getLaboratoryList();
		request.setAttribute("laboratory", laboratory);		
		
		// 加载橱窗列表
		List<java.util.Map> feedList = feedService.getFeedList();
		request.setAttribute("feedList", feedList);
		
		// 加载排行榜
		java.util.Map count = leaderboardService.getGameArticleCount();
		List<java.util.Map> gameTop10 = leaderboardService.getGameTop10();  //热门游戏
		List<java.util.Map> gameRecentTop10 = leaderboardService.getRecentGameTop10();  //最近发售
		List<java.util.Map> articleTop10 = leaderboardService.getArticleTop10();
		
		request.setAttribute("count", count);		
		request.setAttribute("gameTop10", gameTop10);
		request.setAttribute("gameRecentTop10", gameRecentTop10);
		request.setAttribute("articleTop10", articleTop10);		
		
		return mapping.findForward("success");
	}	
}
